package org.holynite.fieldmanage.managed.model

import org.holynite.fieldmanage.ejbs.ChargeManagement
import org.holynite.fieldmanage.entities.ChargeRule

import javax.ejb.EJB
import javax.faces.bean.ManagedBean
import javax.faces.bean.SessionScoped

/**
 * Created by midnite on 15/1/31.
 */
@ManagedBean
@SessionScoped
class ChargeRulesBean implements Serializable {
    List<ChargeRule> rules

    @EJB(beanName = "chargeControl")
    ChargeManagement chargeService

    ChargeRulesBean() {
        rules = []
    }

    void clearRules() {
        rules = []
    }

    void loadRulesInScheme(String scheme, String keyword) {
        rules = chargeService.searchRules(scheme, keyword)
    }

    ChargeRule findRule(String ruleId) {
        rules.find { it.ruleId.equals(ruleId) }
    }
}
